#pragma once
#include <iostream>
#include "log.hpp"
#include "InetAddr.hpp"

using namespace LogModule;

class command
{
public:
    command()
    {
    }
    ~command()
    {
    }

    std::string Excute(const std::string &cmd, InetAddr &addr)
    {
        std::string who = addr.StringAddr();
        FILE *fp = popen(cmd.c_str(), "r");
        if (fp == nullptr)
        {
            return std::string("你要执行的命令不存在") + cmd;
        }
        std::string res;
        char line[1024];
        while (fgets(line, sizeof(line), fp))
        {
            res += line;
        }
        std::string result = who + "excutedone,result is:\n" + res;
        LOG(LogLevel::DEBUG) << result;
        return result;
    }
};